﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Diagnostics;
using System.ComponentModel;
using WPFExcelReport.Helpers;
using System.Windows.Input;
namespace WPFExcelReport
{
    public partial class TWLWS03
    {
        /// <summary>
        /// 16,5,156,1,10,5,10,2,24,1,9,3,7,1,16,3,29,4,14,3,29,1,16,3,7,1,9,2,24,5,10,1,10,0,16,1,8,5,8,2,20,1,6,3,6,1,12,3,24,4,11,3,24,1,12,3,6,1,6,2,20,5,8,1,8,5,137,0,
        ///   第一个代表多少组，每组两个
        ///    然后比如16组，2*32个之后，第一个数字代表循环个数。其中第一个循环有三个，分别第几列到第几列，循环次数
        ///    然后是纬纱
        /// </summary>
        public TWLWS03()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWASTAMM();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
        }

        public override void OnDESChg(string des)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.WABEZ = des.Trim().PadRight(40);
            base.OnDESChg(des);
        }
        public override void Save()
        {
            this.Focus();
            if (dwMaster == null)
                return;


            TMV.UpdateWASTAMM(dwWS, app.company, 0);
            base.Save();
        }
        private void Image_MouseRightButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (!System.IO.File.Exists(PHOTOLINK))
            {
                return;
            }
            if (!System.IO.File.Exists(@"C:\WINDOWS\system32\mspaint.exe"))
            {

                return;
            }
            string PATH = "\"" + PHOTOLINK + "\"";
            ProcessStartInfo pinf = new ProcessStartInfo(@"C:\WINDOWS\system32\mspaint.exe", PATH);
            Process pro = Process.Start(pinf);
            //pro.Start();

        }

        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            IsImageMax = !IsImageMax;
        }
        public override void SaveCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            try
            {
                Update();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            base.SaveCommand(sender, e);
        }
        public override void OnEXAUFChg(string vlaue)
        {
            base.OnEXAUFChg(vlaue);
            TBMain.Clear();
            if (EXAUF.Length < 33)
            {
                return;
            }
            PM["WART"] = EXAUF.Substring(0, 22);
            SResult = TMV.LOADWS(PM);
            MergeData(SResult, true);
            if (!IsAuto)
                return;
            if (TBMain.Rows.Count > 0)
                return;
            PM["ART"] = EXAUF.Substring(0, 20);
            PM["VAR"] = EXAUF.Substring(21, 2);
            PM["BEZ"] = DES;
            PM["PROGRP"] = PRODGRP;
            PM["ARTGRP"] = ARTGRP;
            PM["FDDIM"] = DENUM;
            PM["WABIND"] = Helper.Left("0.00".PadRight(15), 15);
            PM["WAGFKZ"] = "J";
            TMV.NEWWS(PM);
            vwMaster.View.MoveCurrentToFirst();
            NewCommand(null, null);
        }
        public override void LOADBYAUF()
        {
            TBMain.Clear();
            if (ORDERNUM.Length < 23)
            {
                return;
            }
            PM["WART"] = ORDERNUM.Substring(1, 22);
            SResult = TMV.LOADWS(PM);
            MergeData(SResult, true);
            if (!IsAuto)
                return;
            if (TBMain.Rows.Count > 0)
                return;
            PM["ART"] = ORDERNUM.Substring(1, 20);
            PM["VAR"] = ORDERNUM.Substring(21, 2);
            PM["BEZ"] = DES;
            PM["PROGRP"] = PRODGRP;
            PM["ARTGRP"] = ARTGRP;
            PM["FDDIM"] = DENUM;
            PM["WABIND"] = Helper.Left("0.00".PadRight(15), 15);
            PM["WAGFKZ"] = "J";
            TMV.NEWWS(PM);
            vwMaster.View.MoveCurrentToFirst();
            NewCommand(null, null);
        }
    }
}
